package com.workpaper.app.navigation.view.listener;

import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.PartInitException;

import com.workpaper.app.utils.navigation.NavigationUtils;
import com.workpaper.app.utils.platform.SWTPlatformUtils;

public class NavigationMouseListener extends MouseAdapter{
	private Tree navigatTree;
	
	public NavigationMouseListener(Tree navigatTree) {
		super();
		this.navigatTree = navigatTree;
	}

	@Override
	public void mouseUp(MouseEvent e) {
		try {
			TreeItem item = navigatTree.getItem(new Point(e.x, e.y));
			if(item == null) {
				//展开父目录时，这里获取的item是null
				return;
			}
			String viewId = NavigationUtils.getViewId(item.getText());
			SWTPlatformUtils.getActivePage().showView(viewId);	//这里会直接显示到中心区域, 为啥？？？
		} catch (PartInitException e1) {
			e1.printStackTrace();
		}
	}

}
